﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpressHelps.Model;
using ExpressHelps.DAL;
using System.Data;

namespace ExpressHelps.BLL.Task
{
    //创建任务
    public static class TaskCommand
    {
        //创建任务并将订单储存在数据库中
        public static void CreateTask(Tasks.TaskType taskType, string description, string address, int money)
        {
            TaskFactorys.ProduceTask(taskType, description, address, money);
        }
        //通过任务id返回订单
        public static Tasks GetTaskById(int taskId)
        {
            return TaskRepository.GetTaskById(taskId);
        }
        //获得所有未被接取的订单，订单以链表形式存储（可以用来更新订单列表）
        public static DataTable GetTasksUnreceived()
        {
            return TaskRepository.GetTasksUnreceived();
        }
        //通过订单id接取订单
        public static bool ReceiveTask(int taskId)
        {
            Tasks task = new Tasks();
            task = TaskRepository.GetTaskById(taskId);
            if(task.task_id == 0)
            {
                EventMediator.TriggerLogEvent("任务不存在！");
                return false;
            }else if(task.task_isreceiver == true)
            {
                EventMediator.TriggerLogEvent("任务已被接取！");
                return false;
            }else if(task.task_publisher_id == LoginUsers.userId)
            {
                EventMediator.TriggerLogEvent("任务发布者与接取者者为同一人");
                return false;
            }
            else
            {
                if (TaskRepository.ReceiveTask(taskId))
                {
                    return true;
                }
                return false;
            }
            
        }
        //提交投诉,暂时还不用管这个
        public static void PublishComplaint()
        {

        }
        
    }
    
}
